#include <gflags/gflags.h>

#include "asr_server.h"
#include "log.h"

// log
DEFINE_int32(level, 1, "日志等级");
DEFINE_bool(mode, false, "调试模式-false, 发布模式-true");
DEFINE_string(path, "./logfile", "发布模式下日志输出到的文件路径");

// etcd
DEFINE_string(etcd_host, "http://127.0.0.1:2379", "etcd服务器地址");
DEFINE_string(base_service, "/service", "服务监控根目录");
DEFINE_string(instance_name, "/asr/instance", "当前实例名称");
DEFINE_string(access_host, "127.0.0.1:8081", "当前实例的外部访问地址");

// brpc
DEFINE_int32(listen_port, 8081, "监听端口");
DEFINE_int32(idle_timeout_sec, -1, "RPC服务连接超时时间");
DEFINE_int32(num_threads, 1, "RPC服务线程个数");

// asr
DEFINE_string(app_id, "6979407", "app_id");
DEFINE_string(app_key, "9p1Vp23ovppoX960l5mCShn9", "app_key");
DEFINE_string(secret_key, "txotOi5VvppAdMDdSgb72LQh8kzvwzhR", "secret_key");

int main(int argc, char* argv[]) {
    gflags::ParseCommandLineFlags(&argc, &argv, true);
    chat::initLogger(FLAGS_level, FLAGS_mode, FLAGS_path);

    chat::ASRServerBuilder builder;
    builder.makeAsrClient(FLAGS_app_id, FLAGS_app_key, FLAGS_secret_key);
    builder.makeRegisterClient(FLAGS_base_service + FLAGS_instance_name,
                               FLAGS_etcd_host, FLAGS_access_host);
    builder.makeBrpcServer(FLAGS_listen_port, FLAGS_idle_timeout_sec,
                           FLAGS_num_threads);

    chat::ASRServerPtr asr_server = builder.build();
    asr_server->start();

    return 0;
}